#include <stdio.h>
#include <string.h>
#include "Player.h"
void addPlayer(Player players[], int *numPlayers) {
    if (*numPlayers >= 18) {
        printf("球员数量已达上限，无法添加新球员！\n");
        return;
    }
    printf("\n添加球员信息：\n");
    printf("请输入球员姓名：");
    scanf("%s", players[*numPlayers].name);
    printf("请输入球员号码：");
    scanf("%d", &players[*numPlayers].number);
    printf("请输入球员位置：");
    scanf("%s", players[*numPlayers].position);
    printf("请输入球员年龄：");
    scanf("%d", &players[*numPlayers].age);
    printf("请输入球员身高(CM)：");
    scanf("%d", &players[*numPlayers].height);
    printf("请输入球员体重(KG)：");
    scanf("%d", &players[*numPlayers].weight);
    printf("请输入球员薪资(RMB)：");
    scanf("%d", &players[*numPlayers].salary);
    printf("球员信息添加成功！\n");
    (*numPlayers)++;
}

void deletePlayer(Player players[], int *numPlayers) {
    int deleteNumber;
    printf("\n请输入要删除球员的号码：");
    scanf("%d", &deleteNumber);
    int found = 0;
    for (int i = 0; i < *numPlayers; i++) {
        if (players[i].number == deleteNumber) {
            for (int j = i; j < *numPlayers - 1; j++) {
                players[j] = players[j + 1];
            }
            (*numPlayers)--;
            found = 1;
            printf("球员信息删除成功！\n");
            break;
        }
    }
    if (!found) {
        printf("未找到该球员号码对应的球员信息！\n");
    }
}

void modifyPlayer(Player players[], int numPlayers) {
    int modifyNumber;
    printf("\n请输入要修改球员的号码："); 
    scanf("%d", &modifyNumber);
    int found = 0;
    for (int i = 0; i < numPlayers; i++) {
        if (players[i].number == modifyNumber) {
            printf("请输入修改后的球员信息：\n");
            printf("姓名：");
            scanf("%s", players[i].name);
            printf("位置：");
            scanf("%s", players[i].position);
            printf("年龄：");
            scanf("%d", &players[i].age);
            printf("身高(CM)：");
            scanf("%d", &players[i].height);
            printf("体重(KG)：");
            scanf("%d", &players[i].weight);
            printf("薪资(RMB)：");
            scanf("%d", &players[i].salary);
            found = 1;
            printf("球员信息修改成功！\n");
            break;
        }
    }
    if (!found) {
        printf("未找到该球员号码对应的球员信息！\n");
    }
}

void searchPlayer(Player players[], int numPlayers) {
    int searchNumber;
    printf("\n请输入要查询球员的号码：");
    scanf("%d", &searchNumber);
    int found = 0;
    for (int i = 0; i < numPlayers; i++) {
        if (players[i].number == searchNumber) {
            printf("球员信息：\n");
            printf("姓名：%s\n", players[i].name);
            printf("号码：%d\n", players[i].number);
            printf("位置：%s\n", players[i].position);
            printf("年龄：%d\n", players[i].age);
            printf("身高(CM)：%d\n", players[i].height);
            printf("体重(KG)：%d\n", players[i].weight);
			printf("薪资(RMB)：%d\n", players[i].salary);  
            found = 1;
            break;
        }
    }
    if (!found) {
        printf("未找到该球员号码对应的球员信息！\n");
    }
}
 void welcome(){
	printf("                                           **************************** \n");
	printf("                                                足球队信息管理系统       \n"); 
	printf("                                                增加球员数据信息-----1   \n");
	printf("                                                删除球员数据信息-----2   \n");
	printf("                                                修改球员数据信息-----3   \n");
	printf("                                                搜索球员数据信息-----4   \n");
    printf("                                                查询球队近期战绩-----5   \n");
	printf("                                                    Quit-----0          \n");
	printf("                                           ****************************  \n");
    printf("                                                 请输入对应选项：        \n");
}
void print_Player_Date(const char*Teamdate)
{
	FILE*file = fopen(Teamdate,"r");
	if(file == 	NULL){
		printf("未找到该数据");
		return;
	}
	char date[300];
	while(fgets(date,sizeof(date),file)!= NULL){
		printf("%s",date);
	}
	fclose(file);
}